<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<%@ include file="/WEB-INF/jsp/inc/taglibs.jsp"%>
	<%@ include file="/WEB-INF/jsp/inc/meta.jsp"%>
   <script type="text/javascript" src="${approot}/resource/jquery/validate/jquery.validate.js"></script>
   <link href="${approot}/resource/jquery/validate/jquery.validate.css" rel="stylesheet" type="text/css" />
   <link href="${approot}/resource/jquery/validate/style.css" rel="stylesheet" type="text/css" />
     <script type="text/javascript">
            /* <![CDATA[ */
            jQuery(function(){
                jQuery("#addressName").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "地址不能为空"
                });
                jQuery('#address').validated(function(){
					//alert("通过验证");
					do_add();
				});
            });
            /* ]]> */
        </script>
        
        <script type="text/javascript">
        function do_add()
        {   
            var str=$('#address').serializeObject();
            var jsons = $.toJSON(str);
            add_address(jsons);
        }


        function add_address(jsons){
 	       $.ajax({
 		   	url:'${approot}/admin/person/add_address',
 		   	dataType: 'json',
 		   	contentType: 'application/json',
 			data:jsons,
 			type:'post',
 			beforeSend:function(){
 			  // $('#main').disabled='true';
 			},
 			error:function(request){
 				alert(S);
 			},
 			success:function(data){
 			   if(data.msg=="error")
 			   {
 	 			   alert('系统异常，添加失败');
 			   }
 			   if(data.msg=="succ")
 			   {
 				  alert('添加成功');
 				  window.location.reload();
 			   }
 			}
 		   });
 		}
 		
 	 function delete_address(id){  
   		if(confirm('删除后不可恢复,您确认删除该地址信息?')){
  		 	$.ajax({
	 		   	url:'${approot}/admin/person/delete_address/'+id,
	 		   	dataType: 'html',
	 			data:null,
	 			type:'post',
	 			beforeSend:function(){
	 			  // $('#main').disabled='true';
	 			},
	 			error:function(request){
	 				alert(S);
	 			},
	 			success:function(data){
	 			   if(data.msg=="error")
	 			   {
	 	 			   alert('删除失败');
	 			   }
	 			   if(data.msg=="succ")
	 			   {
	 				  alert('删除成功');
	 			   }
	 			   window.location.reload();
	 			}
	 		   });
  		 } 
  	 }
        </script>
   
</head>  
  <body style="background:#E8F5FE; padding:15px 18px;" class="scroll_r">


<form method="post" action="${approot}/admin/person/add_address" id="address">
 
  <table border="0" cellpadding="0" cellspacing="1" width="92%" align="center" id="add_tab">
  <tr>
   <th>姓名：</th>
   <td><input type="text" name="" value="${person.personName }" id="name"><span style="color:#ff0000; margin:0;">*</span></td>
  </tr>
  <tr>
   <th>地址：</th>
   <td><input type="text" name="addressName" value="" id="addressName"><span style="color:#ff0000; margin:0;">*</span></td>
  </tr>
  
 </table>
  <p id="tab_but">
  <input type="hidden" name="personId" value="${person.personId }"/>
   <input type="submit" value="添 加"></p>
   
   <c:choose>
<c:when test="${fn:length(list)<1}">
<div align="center"><font color='red'>此客户尚未添加地址信息!</font></div>
</c:when>
<c:otherwise> 
<table border="0" cellpadding="" cellspacing="1" align="center" width="92%" id="web_tab">
 <tr>
  <th>地址</th>
  <th>添加时间</th>
   <th>操作</th>
 </tr>
<c:forEach var="address" items="${list}">
 <tr>
  <td>
   ${address.addressName }
  </td>
    <td><fmt:formatDate value="${address.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
  <td>
  <a href="#" onclick="return delete_address('${address.addressId}');">删除</a>
   </td>
 </tr>
 </c:forEach>
</table>


</c:otherwise>
</c:choose>
</form>

</body>
</html>
